package com.xhtt.modules.inspection.vo;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.xhtt.common.utils.DateUtils;
import lombok.Data;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/**
 * 综合查询
 *
 * @Date 2019/3/4 16:39
 **/

@Data
public class TaskCompositeVO {


    private Integer taskStepId;

    /**
     * 巡检时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd")
    private LocalDateTime datetime;

    /**
     * 巡检时间计算用得到
     */
    private LocalDateTime endDate;

    /**
     * 线路名称
     */
    private String taskName;

    /**
     * 1日常2固定
     */
    private String lineType;

    /**
     * 巡检类型
     */
    private String inspectType;

    /**
     * 巡检时间段-日班-开始时间
     */
    @JsonFormat(pattern = "HH:mm")
    private LocalDateTime inspectMorningStartDate;

    /**
     * 巡检时间段-日班-结束时间
     */
    @JsonFormat(pattern = "HH:mm")
    private LocalDateTime inspectMorningEndDate;

    /**
     * 巡检时间段-夜班-开始时间
     */
    @JsonFormat(pattern = "HH:mm")
    private LocalDateTime inspectNightStartDate;

    /**
     * 巡检时间段-夜班-结束时间
     */
    @JsonFormat(pattern = "HH:mm")
    private LocalDateTime inspectNightEndDate;

    /**
     * 点击开始巡检的时间
     */
    private LocalDateTime execStartDate;

    /**
     * 巡检时间段
     */
    private String insDate;

    /**
     * 巡检组名称
     */
    private String teamName;

    /**
     * 巡检人员
     */
    private String executor;

    /**
     * 1日班2夜班
     */
    private Integer shiftType;

    /**
     * 有无未签到
     */
    private String isSign;


    public String getDatetime() {
        return DateUtils.df.format(datetime);
    }

    // 时间段
    public String getInsDate() {

        DateTimeFormatter df = DateTimeFormatter.ofPattern("HH:mm");

        String morningStart = null;
        String morningEnd = null;
        String nightStart = null;
        String nightEnd = null;
        String otherStart = null;
        String otherEnd = null;

        if (inspectMorningStartDate != null) {
            morningStart = df.format(inspectMorningStartDate);
        }
        if (inspectMorningEndDate != null) {
            morningEnd = df.format(inspectMorningEndDate);
        }
        if (inspectNightStartDate != null) {
            nightStart = df.format(inspectNightStartDate);
        }
        if (inspectNightEndDate != null) {
            nightEnd = df.format(inspectNightEndDate);
        }
        if (execStartDate != null) {
            otherStart = df.format(execStartDate);
        }
        if (endDate != null) {
            otherEnd = df.format(endDate);
        }
        if (shiftType != null) {
            if (shiftType.equals(1)) {
                return morningStart + "-" + morningEnd;
            } else if (shiftType.equals(2)) {
                return nightStart + "-" + nightEnd;
            }
        } else {
            if (datetime.isAfter(inspectMorningStartDate) && datetime.isBefore(inspectMorningEndDate)) {
                return morningStart + "-" + morningEnd;
            } else if (datetime.isAfter(inspectNightStartDate) && datetime.isBefore(inspectNightEndDate)) {
                return nightStart + "-" + nightEnd;
            } else {
                return otherStart + "-" + otherEnd;
            }
        }
        return null;
    }

}
